<div id="email_sent_ildds" class="easyui-layout tab_a" fit="true">
    <div data-options="region:'center',border:false">
        <table id="email_sent_list"></table>
        <div id="emailsentboxtoolbar" style="padding:5px;height:auto">
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="del_email_list('sent')">删除</a>
            <label style=" float:right;">
                	<input id="email_sent_search_key" class="email_sent_search_form textbox" style="width:200px" type="text">
                	<a href="#" class="easyui-linkbutton email_sent_search_form" iconCls="icon-search" plain="true" onclick="advanced_search('email_sent','email_sent_search_key')">搜索</a>
                <a id="email_sent_advancedSearch" href="javascript:void(0)" class="easyui-linkbutton" plain="true" onclick="advanced_search('email_sent','高级')">高级</a>
            </label>
        </div>
	</div>
</div>
<script>
//发件箱数据构造方法，包括列表属性设置，字段设置，双击设置
$('#email_sent_list').datagrid({
    url:'<?php echo base_url('email/getsentboxlistdata');?>',
	method:'post',
	singleSelect:true,
	selectOnCheck:false,
	pagination:true,
	pageSize:30,
	pageList:[30,50,100],
	fit:true,
	fitColumns:true,
	border:false,
	queryParams:{},
	sortName:'bodyid',
	sortOrder:'desc',
	toolbar:'#emailsentboxtoolbar',
    columns:[[
		{field:'bodyid',checkbox:true},
		{field:'isread',title:'状态',width:10,align:'center',
			formatter: function(value,row,index){
				return "<div onclick='javascript:read_status("+row.bodyid+")'>查看</div>";
			}
		},
        {field:'addressee2',title:'收件人',width:16,align:'center',
			formatter: function(value,row,index){
				return subStringCh(value,8,true);
			}
		},
        {field:'title',title:'标题',width:200},
		{field:'isattach',title:'附件',width:10,align:'center',
			formatter: function(value,row,index){
				if(value != '' || value != 0){
					return "<div class='icon-attach' style='height: 16px;'></div>";
				}
			}
		},
        {field:'sendertime',title:'发送时间',width:30,align:'center',sortable:'true',
			formatter: function(value,row,index){
				//return getLocalTime(value);
				return value;
			}
		}
    ]],
	onDblClickRow:function(index,data){
		//var row=$('#email_sent_list').datagrid('getSelected');
		//if(row){/**当前的tab 是否存在如果存在就 自动选择 否则 创建新的tab**/
		var title = (strlen(data.title) >10)?SetString(data.title,10)+'..':data.title;//如果标题超过10个字符，则截取10个字符加..
		var ef_id = 'ef_'+data.id; //拼接面板ID
		var ef_obj = $('#main-tab').find("#"+ef_id);//获取面板ID对象对象
			
		//var title = 'EF'+row.bodyid+':'+SetString(row.title,16);
		if (ef_obj.length>0){ 
			var tab_index = ef_obj.parent().index();//检查该对象的父元素在其父元素中的索引
			$('#main-tab').tabs('select', tab_index); 
		} else {
			/**添加一个tab标签**/
			$("#main-tab").tabs('add',{
				title: '发件箱:'+title,
				href: '<?php echo base_url();?>email/contentbox/sent/'+data.bodyid,
				tabWidth:'160',
				selected: true,
				closable:true,
				onLoad:function(){ 
					//为面板添加详细标题属性 
					var item1 = $('.tabs-selected').find("span:first");
					$('#main-tab').find(item1).attr("title",data.title);
				}
			});
			
		}
		//}
	},
	onLoadSuccess:function(){
        var pager = $(this).datagrid('getPager');
        pager.pagination({
            displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录'
        });
    }
});

//查看收件人详细状态
function read_status(bodyid){
	$('#read_status').dialog({
		title: '签收情况 - 删除后对方将无法收到',
		iconCls:'icon-search',
		toolbar: [{
			text:'删除',
			iconCls:'icon-cancel',
			handler:function(){
				delEmailuserbox();
			}
		}],
		width: 500,
		height: 400,
		closed: false,
		resizable:true,
		cache: false,
		modal: true
	});

	$('#readStatusView').datagrid({
		url:'<?php echo base_url('email/read_status');?>/'+bodyid,
		rownumbers:true,
		singleSelect:true,		
		selectOnCheck:false,
		fitColumns:true,
		border:false,
		columns:[[
			{field:'id',checkbox:true},
			{field:'read',title:'状态',width:50,align:'center',
				formatter: function(value,row,index){
					if(row.del == 1){
						return "<div class='icon-arrow-cross' style='height: 16px;' title='已删除'></div>";
					}else if(value == 0){
						return "<div class='icon-email' style='height: 16px;' title='未读'></div>";	
					}else if(value == 1){
						return "<div class='icon-email-open-gray' style='height: 16px;' title='已读'></div>";	
					}
				}
			},
			{field:'addressee',title:'收件人',width:100,align:'center'},
			{field:'readtime',title:'收件时间',width:100,align:'center',
				formatter: function(value,row,index){
					//return (value != 0)?getLocalTime(value):'';
					return value;
				}
			}
		]],
		onLoadSuccess : function(data){
			if(data.total == 0){//收件人列表加载成功后检查是否有内容，如果没有内容则证明收件人和邮件主题已经被删除不，则执行关闭窗口、刷新发件箱列表的操作
				$('#email_sent_list').datagrid('reload');
				$('#read_status').dialog('close');	
			}
		}
	});
	//$('#read_status').dialog('open');//数据构造完成后，打开窗口
}

//"删除详细收件人"函数
function delEmailuserbox(){
	var getobj = $('#readStatusView').datagrid("getChecked");
	var getid = [];
		$.each(getobj, function(index, item){
			getid.push(item.id);
		}); 
	if(getid.length == 0){
		$.messager.alert('提示','要删除已发邮件，请选取要操作的行','warning');
	}else{  
	   $.messager.confirm('提示', '确定要删除选中的邮件吗?', function(r){
			if(r){       
				$.post("<?php echo base_url('email/sentuserboxdel');?>",{getid:getid},function(result){
					if(result.success){
						$('#readStatusView').datagrid('reload');
						$('#email_sent_list').datagrid('reload');
						if ($('#main-tab').tabs('exists', '收件箱')){//如果收件箱标签面板已经打开，则刷新收件箱数据列表，防止数据不同步
							$('#emailinlist').datagrid('reload');
						}
					}else{
						$.messager.alert('错误',result.errorMsg,'error');
					}
				},'json');
			}
		});	
	}
}

</script>